<template>
  <el-row type="flex" justify="space-between" :gutter="24">
    <el-col>
      <span> {{ departs.name }}</span>
    </el-col>
    <el-col :span="3">
      <el-row type="flex">
        <el-col>
          {{ departs.manager }}
        </el-col>
        <!-- 下拉模块  -->
        <el-col>
          <el-dropdown @command="deleteSection">
            <span class="el-dropdown-link">
              操作 <i class="el-icon-arrow-down" />
            </span>
            <!-- element 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                v-for="(item, index) in headObj"
                :key="index"
                :command="index"
              >{{ item }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { removeSectionApi } from '@/api'
export default {
  name: 'VueAdminTemplateMasterTreeTools',
  props: {
    // 树形结构数据
    departs: {
      type: Object,
      required: true // 必传项
    },
    // 选择框选项
    headObj: {
      type: Array,
      required: true // 必传项
    }
  },
  data() {
    return {}
  },

  mounted() {},

  methods: {
    deleteSection(command) {
      // 添加
      if (command === 0) {
        // 触发父主件自定义事件  传入点击的此节点树形结构数据
        this.$emit('addSection', this.departs)
        // 编辑
      } else if (command === 1) {
        // 将当前点击节点信息传到父组件事件中
        this.$emit('compile', this.departs)
      } else {
        // 删除
        // this.departs.id获取当前 props传过来当前节点的id
        this.$confirm('此操作删除该部门, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            return removeSectionApi(this.departs.id) // 返回请求成功结果
          })
          .then(() => {
            this.$emit('delDepls') // 触发父主件事件
            this.$message.success('删除部门成功')
          })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
